#include <retro.h>
#include "retro.library.h"
#include "retro.fmodaudio.h"

#ifdef _M_X64
#if defined(DEBUG) || defined(_DEBUG)
#pragma comment(lib, "fmodexL64_vc.lib")
#else
#pragma comment(lib, "fmodex64_vc.lib")
#endif
#else
#if defined(DEBUG) || defined(_DEBUG)
#pragma comment(lib, "fmodexL_vc.lib")
#else
#pragma comment(lib, "fmodex_vc.lib")
#endif
#endif

#define FMOD_ERRCHECK(x) if ((x) != FMOD_OK) return FALSE;
#define FMOD_RELEASE(x)  if (x) { x->release(); x = NULL; }

using namespace Retro;
using namespace Retro::Device;
using namespace Retro::Device::Audio;

FMODAudio::FMODAudio() :
  AudioDevice(Device::LibraryFMOD)
{
  mFMODSystem = NULL;
}

BOOL FMODAudio::initialize()
{
  FMOD_ERRCHECK(FMOD::System_Create(&mFMODSystem));

  return TRUE;
}

BOOL FMODAudio::uninitialize()
{
  FMOD_RELEASE(mFMODSystem);

  return TRUE;
}

BOOL FMODAudio::isInitialized()
{
  return mFMODSystem > 0;
}
